﻿using System;

namespace ShareHelper
{
    /// <summary>
    /// 获取时间戳
    /// </summary>
    public static class TimeStamp
    {
        #region 13位

        /// <summary>
        /// 获取十三位 文本时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetTimeStampStr()
        {
            return DateTime.UtcNow.GetTimeStampStr();
        }

        /// <summary>
        /// 获取十三位 文本时间戳
        /// </summary>
        /// <param name="date">转换时间</param>
        /// <returns></returns>
        public static string GetTimeStampStr(this DateTime date)
        {
            return date.GetTimeStamp().ToString();
        }

        /// <summary>
        /// 十三位时间戳
        /// </summary>
        /// <returns></returns>
        public static long GetTimeStamp()
        {
            return DateTime.UtcNow.GetTimeStamp();
        }

        /// <summary>
        ///十三位时间戳
        /// </summary>
        /// <param name="date">转换时间</param>
        /// <returns></returns>
        public static int GetTimeStamp(this DateTime date)
        {
            return (int)new DateTimeOffset(date).ToUnixTimeMilliseconds();
        }

        #endregion 13位

        #region 10位

        /// <summary>
        /// 获取十位 文本时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetTimeStampStr_10()
        {
            return DateTime.UtcNow.GetTimeStampStr_10();
        }

        /// <summary>
        /// 获取十位 文本时间戳
        /// </summary>
        /// <param name="date">转换时间</param>
        /// <returns></returns>
        public static string GetTimeStampStr_10(this DateTime date)
        {
            return date.GetTimeStamp_10().ToString();
        }

        /// <summary>
        /// 十位时间戳
        /// </summary>
        /// <returns></returns>
        public static int GetTimeStamp_10()
        {
            return DateTime.UtcNow.GetTimeStamp_10();
        }

        /// <summary>
        ///十位时间戳
        /// </summary>
        /// <param name="date">转换时间</param>
        /// <returns></returns>
        public static int GetTimeStamp_10(this DateTime date)
        {
            return (int)new DateTimeOffset(date).ToUnixTimeSeconds();
        }

        #endregion 10位
    }
}